package com.xdf.teacher.activity;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.xdf.teacher.R;

import net.neiquan.applibrary.base.BaseActivity;
import net.neiquan.applibrary.wight.AlertDialog;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by JavaDog on 2018-3-21.
 */

public class LiveActivity extends Activity {
    @InjectView(R.id.stream_layout)
    LinearLayout stream_layout;
    @InjectView(R.id.mTeacherName)
    TextView mTeacherName;
    @InjectView(R.id.mVideoLogo)
    ImageView mVideoLogo;
    @InjectView(R.id.mVoiceLogo)
    ImageView mVoiceLogo;
    @InjectView(R.id.mListenLogo)
    ImageView mListenLogo;
    @InjectView(R.id.mSeeLogo)
    ImageView mSeeLogo;
    @InjectView(R.id.mExitLogo)
    ImageView mExitLogo;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_live);
        ButterKnife.inject(this);
    }

    private boolean videoFlag=true;
    private boolean voiceFlag=true;
    private boolean listenFlag=true;
    private boolean seeFlag=true;
    @OnClick({R.id.mVideoLogo,R.id.mVoiceLogo,R.id.mListenLogo,R.id.mSeeLogo,R.id.mExitLogo})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.mVideoLogo:
                videoFlag=!videoFlag;
                mVideoLogo.setImageResource(videoFlag?R.drawable.video:R.drawable.video_not);
                break;
            case R.id.mVoiceLogo:
                voiceFlag=!voiceFlag;
                mVoiceLogo.setImageResource(voiceFlag?R.drawable.voice:R.drawable.voice_not);
                break;
            case R.id.mListenLogo:
                listenFlag=!listenFlag;
                mListenLogo.setImageResource(listenFlag?R.drawable.listen:R.drawable.listen_not);
                break;
            case R.id.mSeeLogo:
                seeFlag=!seeFlag;
                mSeeLogo.setImageResource(seeFlag?R.drawable.see:R.drawable.see_not);
                break;
            case R.id.mExitLogo:
                new AlertDialog.Builder(LiveActivity.this).setTitle("是否确认退出?")
                        .setPositiveButton("退出", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        })
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).create().show();
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            exit();
            return false;
        }
        return super.onKeyDown(keyCode, event);
    }

    private long exitTime = 0;

    public void exit() {
        if ((System.currentTimeMillis() - exitTime) > 2000) {
            Toast.makeText(getApplicationContext(), "再按一次退出直播间",
                    Toast.LENGTH_SHORT).show();
            exitTime = System.currentTimeMillis();
        } else {
            finish();
//            System.exit(0);
        }
    }

}
